package com.bcl.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;

//使用方法比较简单，新建一个类实现 BeanPostProcessor 接口，并将该类注册到 Spring IoC 容器中。
//这样，在 Spring 创建 bean 实例时，执行初始化方法前会调用
// TestBeanPostProcessor 的 postProcessBeforeInitialization 方法，
// 在执行初始化方法后会调用 TestBeanPostProcessor 的 postProcessAfterInitialization 方法。
@Component
public class TestBeanPostProcessor implements BeanPostProcessor, PriorityOrdered {

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

		System.out.println("TestBeanPostProcessor##postProcessBeforeInitialization");

		//逻辑
		return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

		System.out.println("TestBeanPostProcessor##postProcessAfterInitialization");

		return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
	}
}
